<head>
<title>เวปบอร์ดแบบเก็บข้อมูลใน DataBase (สำหรับ Admin)</title>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-874">
<META HTTP-EQUIV="Expires" CONTENT="0">
<link href="./style.css" rel="stylesheet" type="text/css">
</head>
<?
	include("./config.inc.php");	//ตั้งค่าต่างๆของเวปบอร์ด
	include("./function.inc.php");		//ฟังก์ชั่นที่ใช้ในเวปบอร์ด
  if(!$Category || !$No){
	  //ไม่ม
	  echo Message(50,"red","ไม่กำหนดหมายเลขคำถาม","มีปัญหาในการแสดงข้อมูล","<a href='javascript:history.go(-1)'>ย้อนกลับ</a>");
	  exit();
}

	// อ่านค่า Key จากไฟล์
	if(file_exists("key.pass")) {
		$FILE=fopen("key.pass","rt");
		$key_in_file=fgets($FILE,15);	// Key กำหนดอยู่ในไฟล์ 12 ตัว ฉะนั้นต้องอ่านมา มากกว่า 12 ในที่นี้ใช้ 15 ตัว
		fclose($FILE);
	}

	if($key!=$key_in_file) {
		echo Message(65,"red","ไม่อนุญาตให้เข้าใช้หน้า Admin (ลบคำถาม - คำตอบ)","อาจเพราะ Username และหรือ Password ไม่ถูกต้อง<br>หรือยังไม่ได้ Login เข้าระบบ","<a href='./login.php?Category=$Category'>Login อีกครั้ง</a>");
		exit();
	}

?>

<body bgcolor=#FFFFE0>
<center><p align="CENTER"><br>
<b><font face="LilyUPC" size="+4" color=#9400d3>เวปบอร์ดแบบเก็บข้อมูลใน Database</font></b><br>เพื่อแลกเปลี่ยนความรู้, ถาม-ตอบปัญหาคาใจ, แนะนำ, ประกาศ, หรือทุกสิ่งตามต้องการ 
<br><br><font color=green class=size3><b>สำหรับเวปมาสซะเตอร์ (ลบคำถาม - คำตอบ)</b></font>
</p>
<div align="center">[ <a href="./admin.php?key=<?echo$key;?>&Category=<?echo $Category;?>">กลับหน้าหลัก Admin</a> ]</div><br>
<?
@mysql_connect($host,$user,$pwd);
$sql="select * from board_data Where Category='$Category' and No='$No'";
$result=mysql_db_query($dbname,$sql);
$NRow=mysql_num_rows($result);
if($NRow!=0){
	$row = mysql_fetch_array($result);
	$e=$row['Email'];
	$n=$row['Name'];
	$name = ($e=="") ? $row['Name'] : "<a href=\"mailto:$e\">$n</a>";
?>
<table width=600 border=0 cellspacing=0 cellpadding=0 align=center bgcolor=#FFFFFF>
<tr><td valign=top width=9 bgcolor=#0000FF><img src="pic/b_top_left.gif" border=0></td>
<td width=583 bgcolor=#0000FF><table width=100% border=0 cellspacing=0 cellpadding=5>
<tr align=center><td><font color=#FFFFFF class=size3><b><?echo $row['Subject'];?></b></font></td></tr>
</table></td><td width=9 align=right valign=top bgcolor=#0000FF><img src="pic/b_top_right.gif"></td></tr>
<tr><td width=9 background="pic/b_line_left.gif" valign=top><img src="pic/tc.gif"></td>
<td width=583><table width=100% border=0 cellspacing=0 cellpadding=5>
<tr><td height=50><?echo $row['Note'];?></td></tr></table></td>
<td width=9 background="pic/b_line_right.gif" valign=top align=right><img src="pic/tc.gif"></td></tr>
<tr><td width=9 valign=top background="pic/b_line_ver1.gif"><img src="pic/b_line_ver1.gif"></td>
<td width=583 background="pic/b_line_ver2.gif"><img src="pic/tc.gif"></td>
<td width=9 align=right valign=top background="pic/b_line_ver2.gif"><img src="pic/b_line_ver3.gif"></td></tr>
<tr><td width=9 background="pic/b_line_left.gif" valign=top><img src="pic/tc.gif"></td>
<td width=583 align=right><?echo $name," [",$row['Day'],"]";?></td>
<td width=9 background="pic/b_line_right.gif" valign=top align=right><img src="pic/tc.gif"></td>
</tr><tr><td width=9 valign=top height=9><img src="pic/b_bottom_left.gif"></td>
<td width=583 background="pic/b_line_bottom.gif" height=9 valign=top><img src="pic/tc.gif"></td>
<td width=9 align=right valign=top height=9><img src="pic/b_bottom_right.gif"></td></tr></table>
<br>
<?
}
$sql="select * from board_ans Where QNo='$No' and Category='$Category' order by No ASC";
$result=mysql_db_query($dbname,$sql);
$NRow=mysql_num_rows($result);
if($result==0){
	echo "Error";
	exit();
}
$n2=1;
while ($row = mysql_fetch_array($result)) {
	$QNo=$row['QNo'];
	$n=$row['Name'];
	$Note=$row['Note'];
	$e = $row["Email"];
	$Day = $row["Day"];
	$name = ($e=="") ? $row['Name'] : "<a href=\"mailto:$e\">$n</a>";
	echo ("<table width=600 border=0 cellspacing=0 cellpadding=0 align=center bgcolor=#99CCFF>\n");
	echo ("<tr valign=top><td width=9><img src=\"pic/b_top_left1.gif\"></td>\n");
	echo ("<td width=580 background=\"pic/b_line_top.gif\"><img src=\"pic/tc.gif\"><img src=\"pic/b_line_top.gif\"></td>\n");
	echo ("<td align=right width=9><img src=\"pic/b_top_right1.gif\"></td></tr>\n");
	echo ("<tr><td width=9 background=\"pic/b_line_left.gif\" valign=top><img src=\"pic/tc.gif\"></td>\n");
	echo ("<td width=581><table width=100% border=0 cellspacing=0 cellpadding=5><tr valign=top> \n");
	echo ("<td height=50>");
	echo ("$Note</td></tr></table></td>\n");	
	echo ("<td width=9 background=\"pic/b_line_right.gif\" valign=top align=right><img src=\"pic/tc.gif\"></td>\n");
	echo ("</tr><tr><td width=9 valign=top background=\"pic/b_line_left.gif\"><img src=\"pic/tc.gif\"></td>\n");
	echo ("<td width=581><img src=\"pic/tc.gif\"><img src=\"pic/tc.gif\"></td>\n");
	echo ("<td width=9 align=right valign=top background=\"pic/b_line_right.gif\"><img src=\"pic/tc.gif\"></td></tr>\n");
	echo ("<tr><td width=9 background=\"pic/b_line_left.gif\" valign=top><img src=\"pic/tc.gif\"></td>\n");
	echo ("<td width=581>$name [ $Day ]</td>\n");
	echo ("<td width=9 background=\"pic/b_line_right.gif\" valign=top align=right><img src=\"pic/tc.gif\"></td>\n");
	echo ("</tr><tr><td width=9 valign=top height=9> <img src=\"pic/b_bottom_left1.gif\"></td>\n");
	echo ("<td width=581 background=\"pic/b_line_bottom.gif\" height=9 valign=top><img src=\"pic/tc.gif\"></td>\n");
	echo ("<td width=9 align=right valign=top height=9><img src=\"pic/b_bottom_right1.gif\"></td></tr></table>\n");
	echo "<br>\n";
	echo "[ <a href=\"./edit.php?key=$key&Category=$Category&select=1&admin_Q=$No&admin_R=",$row['No'],"\">ลบคำตอบที่ $n2</a> ]<br><br>\n";
	$n2++;
}
?>
<br>
</center>
<br>
</body>
</html>